/* 统一代码块样式 - 基于md-editor-v3 */

/* 基本CSS变量定义 */
:root {
  /* 代码相关变量 - 浅色主题 */
  --md-theme-code-inline-color: #3594f7;
  --md-theme-code-inline-bg-color: rgba(59, 170, 250, 0.1);
  --md-theme-code-inline-radius: 2px;
  --md-theme-code-block-color: #a9b7c6;
  --md-theme-code-block-bg-color: #282c34;
  --md-theme-code-before-bg-color: var(--md-theme-code-block-bg-color);
  --md-theme-code-block-radius: 5px;
  --md-theme-code-copy-tips-color: inherit;
  --md-theme-code-copy-tips-bg-color: #fff;
  --md-theme-code-active-color: #61aeee;
  
  /* 通用变量 */
  --md-theme-radius-s: 2px;
  --md-theme-radius-m: 5px;
  --md-theme-border-color: #e6e6e6;
}

/* 暗色主题变量 */
[data-theme="dark"], .dark-theme {
  --md-theme-code-inline-color: #3594f7;
  --md-theme-code-inline-bg-color: rgba(59, 170, 250, 0.1);
  --md-theme-code-block-color: #a9b7c6;
  --md-theme-code-block-bg-color: #1a1a1a;
  --md-theme-code-before-bg-color: var(--md-theme-code-block-bg-color);
  --md-theme-code-copy-tips-bg-color: #3a3a3a;
  --md-theme-code-active-color: #e6c07b;
}

/* 内联代码样式 */
.unified-content code:not(.md-editor-code-block) {
  color: var(--md-theme-code-inline-color);
  background-color: var(--md-theme-code-inline-bg-color);
  border-radius: var(--md-theme-code-inline-radius);
  padding: 2px 4px;
  line-height: 22px;
  font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace;
}

/* 代码块容器样式 */
.unified-content .md-editor-code,
.unified-content .code-block-wrapper {
  color: var(--md-theme-code-block-color);
  font-size: 12px;
  line-height: 1;
  margin: 20px 0;
  position: relative;
}

/* 代码块头部样式 */
.unified-content .md-editor-code-head,
.unified-content .code-block-header {
  display: grid;
  grid-template: "1fr 1fr";
  justify-content: space-between;
  height: 32px;
  width: 100%;
  font-size: 12px;
  background-color: var(--md-theme-code-before-bg-color);
  margin-bottom: 0;
  border-top-left-radius: var(--md-theme-code-block-radius);
  border-top-right-radius: var(--md-theme-code-block-radius);
  -webkit-tap-highlight-color: rgba(0,0,0,0);
  list-style: none;
  position: sticky;
  top: 0;
  z-index: 10000;
}

/* 代码块标志 */
.unified-content .md-editor-code-flag,
.unified-content .code-block-flag {
  margin-left: 12px;
}

.unified-content .md-editor-code-flag span,
.unified-content .code-block-flag span {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 11px;
}

.unified-content .md-editor-code-flag span:nth-of-type(1),
.unified-content .code-block-flag span:nth-of-type(1) {
  background-color: #ec6a5e;
}

.unified-content .md-editor-code-flag span:nth-of-type(2),
.unified-content .code-block-flag span:nth-of-type(2) {
  background-color: #f4bf4f;
}

.unified-content .md-editor-code-flag span:nth-of-type(3),
.unified-content .code-block-flag span:nth-of-type(3) {
  background-color: #61c554;
}

.unified-content .md-editor-code-flag span + span,
.unified-content .code-block-flag span + span {
  margin-left: 4px;
}

/* 代码块语言标签 */
.unified-content .md-editor-code-lang,
.unified-content .code-block-lang {
  line-height: 32px;
}

/* 代码块动作按钮 */
.unified-content .md-editor-code-action,
.unified-content .code-block-actions {
  display: flex;
  align-items: center;
}

.unified-content .md-editor-code-action > *,
.unified-content .code-block-actions > * {
  margin-right: 10px;
}

/* 复制按钮样式 */
.unified-content .md-editor-copy-button,
.unified-content .copy-button {
  cursor: pointer;
  line-height: 32px;
  position: initial;
}

.unified-content .md-editor-copy-button .md-editor-icon,
.unified-content .copy-button .icon {
  width: 15px;
  height: 15px;
  display: inline-block;
  vertical-align: sub;
}

/* 代码块内容样式 */
.unified-content .md-editor-code pre,
.unified-content .code-block pre {
  position: relative;
  margin: 0;
}

.unified-content .md-editor-code pre code,
.unified-content .code-block pre code,
.unified-content pre code {
  font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace;
  font-size: 14px;
  color: var(--md-theme-code-block-color);
  background-color: var(--md-theme-code-before-bg-color);
  display: block;
  line-height: 1.6;
  overflow: auto;
  padding: 1em;
  position: relative;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-bottom-left-radius: var(--md-theme-code-block-radius);
  border-bottom-right-radius: var(--md-theme-code-block-radius);
}

/* 代码块内容容器 */
.unified-content .md-editor-code pre code .md-editor-code-block,
.unified-content .code-block pre code .code-content {
  display: inline-block;
  width: 100%;
  overflow: auto;
  vertical-align: bottom;
  color: var(--md-theme-code-block-color);
}

/* 行号样式 */
.unified-content .md-editor-scrn span[rn-wrapper] {
  position: absolute;
  pointer-events: none;
  top: 1em;
  font-size: 100%;
  left: 0;
  width: 3em;
  letter-spacing: -1px;
  user-select: none;
  counter-reset: linenumber;
}

.unified-content .md-editor-scrn span[rn-wrapper] > span {
  display: block;
  pointer-events: none;
  counter-increment: linenumber;
}

.unified-content .md-editor-scrn span[rn-wrapper] > span::before {
  color: #999;
  display: block;
  padding-right: 0.5em;
  text-align: right;
  content: counter(linenumber);
}

.unified-content .md-editor-scrn pre code {
  padding-left: 3.5em !important;
}

/* 滚动条样式 */
.unified-content ::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.unified-content ::-webkit-scrollbar-button:vertical {
  display: none;
}

.unified-content ::-webkit-scrollbar-corner,
.unified-content ::-webkit-scrollbar-track {
  border-radius: 2px;
  background-color: #e2e2e2;
}

.unified-content ::-webkit-scrollbar-thumb {
  border-radius: 2px;
  background-color: rgba(0,0,0,.3019607843);
}

.unified-content ::-webkit-scrollbar-thumb:vertical:hover {
  background-color: rgba(0,0,0,.3490196078);
}

.unified-content ::-webkit-scrollbar-thumb:vertical:active {
  background-color: rgba(0,0,0,.3803921569);
}

/* 暗色主题滚动条 */
[data-theme="dark"] .unified-content ::-webkit-scrollbar-corner,
[data-theme="dark"] .unified-content ::-webkit-scrollbar-track,
.dark-theme .unified-content ::-webkit-scrollbar-corner,
.dark-theme .unified-content ::-webkit-scrollbar-track {
  background-color: #0f0f0f;
}

[data-theme="dark"] .unified-content ::-webkit-scrollbar-thumb,
.dark-theme .unified-content ::-webkit-scrollbar-thumb {
  background-color: #2d2d2d;
}

[data-theme="dark"] .unified-content ::-webkit-scrollbar-thumb:vertical:hover,
[data-theme="dark"] .unified-content ::-webkit-scrollbar-thumb:vertical:active,
.dark-theme .unified-content ::-webkit-scrollbar-thumb:vertical:hover,
.dark-theme .unified-content ::-webkit-scrollbar-thumb:vertical:active {
  background-color: #3a3a3a;
}

/* 兼容性样式 - 针对不同的代码块结构 */
.unified-content pre[class*="language-"] {
  font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace;
  font-size: 14px;
  color: var(--md-theme-code-block-color);
  background-color: var(--md-theme-code-block-bg-color);
  line-height: 1.6;
  overflow: auto;
  padding: 1em;
  margin: 20px 0;
  border-radius: var(--md-theme-code-block-radius);
}

.unified-content pre[class*="language-"] code {
  color: var(--md-theme-code-block-color);
  background-color: transparent;
  padding: 0;
  font-size: inherit;
}

/* 确保在不同容器中的样式一致性 */
.article-content .unified-content,
.markdown-content .unified-content,
.md-editor-preview .unified-content {
  /* 继承所有上述样式 */
}